import sys

# main_num = int(input())
# num_list = [int(i) for i in input().split()]

main_num = 28
num_list = tuple([int(i) for i in '1507 6611 20966 571 1023 9390 16632 16742 12152 18621 4670 25368 15333 7461 12737 24979 10819 1505 13802 20395 6112 18161 23373 9154 14116 24391 27280 27686'.split()])


def is_prime(n):
    if n == 1:
        return 1
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
           return 0
    return 1

cache = {}

def cachee(num_list):
    if num_list in cache:
        return cache[num_list]
    cache[num_list] = main(num_list)
    return cache[num_list]

def main(num_list):
    if len(num_list) == 2:
        return  is_prime(num_list[0] + num_list[1])
    if not num_list:
        return 0
    a1 = num_list[0]
    result = 0
    next_prime_list = []
    next_no_prime_list = []

    for i in range(1, len(num_list)):
        a2 = num_list[i]
        new_list = list(num_list[1:])
        new_list.pop(i-1)
        new_list = tuple(new_list)

        new_result = cachee(new_list) + cachee((a1, a2))
        if new_result > result:
            result = new_result
    return result

x = cachee(num_list)
print(x)



